package com.aramis.mydytt.ui.topic.detail

import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import com.aramis.mydytt.ui.base.BaseViewHolder
import com.aramis.mydytt.ui.bean.MovieSpecialDetailBean
import com.aramis.mydytt.ui.bean.MovieSpecialDetailItemBean

/**
 * Description: TopicDetailListAdapter
 * @author lizhidan
 * Created: 2021/5/24
 */
class TopicDetailListAdapter : RecyclerView.Adapter<BaseViewHolder<MovieSpecialDetailBean>>() {
    private val typeTitle = 1
    private val typeItem = 2
    private var dataBean: MovieSpecialDetailBean? = null
    var onMovieItemClickListener: ((MovieSpecialDetailItemBean) -> Unit)? = null

    fun setDataBean(dataBean: MovieSpecialDetailBean?) {
        this.dataBean = dataBean
        if (dataBean != null) {
            notifyDataSetChanged()
        }
    }

    override fun getItemViewType(position: Int): Int {
        return if (position == 0) typeTitle else typeItem
    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): BaseViewHolder<MovieSpecialDetailBean> {
        val isTitle = viewType == typeTitle
        return if (isTitle) TopicDetailListAdapterTitleViewHolder(parent) else TopicDetailListAdapterItemViewHolder(
            parent,
            onMovieItemClickListener
        )
    }

    override fun onBindViewHolder(holder: BaseViewHolder<MovieSpecialDetailBean>, position: Int) {
        if (dataBean != null) {
            holder.bind(dataBean!!, position)
        }
    }

    override fun getItemCount(): Int = if (dataBean != null && dataBean!!.video != null) 1 + dataBean!!.video!!.size else 0


}